package cc.ufinity.networkdiagnose.widget;

import cc.ufinity.networkdiagnose.manager.Task;
import cc.ufinity.networkdiagnose.manager.WlanManager;
import cc.ufinity.networkdiagnose.view.R;
import android.app.Activity;
import android.net.ConnectivityManager;
import android.view.View;
import android.widget.Button;

public class SelectNetType extends GeneralTestWidget implements View.OnClickListener {
    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Activity ctx;
    private Task task;
    private TaskDetailWidget tdw;
    private WlanManager wlanManager;
    private Button btnBack;
    
    private Task_Test_Widget ttw;

    public SelectNetType(Activity context) {
        super(context);
        inflate(context, R.layout.nettype, this);
        btn1 = (Button) this.findViewById(R.id.button1);
        btn2 = (Button) this.findViewById(R.id.button2);
        btn3 = (Button) this.findViewById(R.id.button3);
        btnBack = (Button) this.findViewById(R.id.btn_nettype_back);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        this.ctx = context;
        task = (Task) ctx.getIntent().getSerializableExtra(TAG_REFER_TASK);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1:
            task.selNetType = ConnectivityManager.TYPE_WIFI;
            ctx.getIntent().putExtra(TAG_REFER_TASK, task); 
            tdw = new TaskDetailWidget(ctx);
            ctx.setContentView(tdw);
        	/*wlanManager = new WlanManager(ctx);
            task.selNetType = ConnectivityManager.TYPE_WIFI;
            ctx.getIntent().putExtra(TAG_REFER_TASK, task);
            ttw = new Task_Test_Widget(ctx);
            ctx.setContentView(ttw);*/
            break;
        case R.id.button2:
            wlanManager = new WlanManager(ctx);
            wlanManager.closeWifi();
            task.selNetType = ConnectivityManager.TYPE_MOBILE;
            ctx.getIntent().putExtra(TAG_REFER_TASK, task);
            tdw = new TaskDetailWidget(ctx);
            ctx.setContentView(tdw);
            break;
        case R.id.button3:
        	 wlanManager = new WlanManager(ctx);
             wlanManager.closeWifi();
             task.selNetType = ConnectivityManager.TYPE_MOBILE;
             ctx.getIntent().putExtra(TAG_REFER_TASK, task);
             tdw = new TaskDetailWidget(ctx);
             ctx.setContentView(tdw);
            break;
        case R.id.btn_nettype_back:
            this.backToTask(ctx);
            break;

        }

    }

}
